package com.kuang.service.product;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuang.entity.Product;
import com.kuang.mapper.ProductMapper;
import com.kuang.vo.ProductVo;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper,Product> implements ProductService {


    public Page<Product> findProductByPage(ProductVo productVo){
        Page<Product> page = new Page<>(productVo.getPageNo(), productVo.getPageSize());
        LambdaQueryWrapper<Product> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(productVo.getCategoryPid()!=null,Product::getCategoryPid,productVo.getCategoryPid());
        lambdaQueryWrapper.eq(productVo.getCategoryCid()!=null,Product::getCategoryCid,productVo.getCategoryCid());
        lambdaQueryWrapper.eq(Product::getStatus,1);
        lambdaQueryWrapper.orderByDesc(Product::getCreateTime);
        return   this.page(page,lambdaQueryWrapper);
    }

//    public Page<Product> findIndex(ProductVo productVo){
//        Page<Product> page = new Page<>(productVo.getPageNo(), productVo.getPageSize());
//        LambdaQueryWrapper<Product> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(productVo.getCategoryPid()!=null,Product::getCategoryPid,productVo.getCategoryPid());
//        lambdaQueryWrapper.eq(productVo.getCategoryCid()!=null,Product::getCategoryCid,productVo.getCategoryCid());
//        lambdaQueryWrapper.eq(Product::getStatus,1);
//        lambdaQueryWrapper.orderByDesc(Product::getCreateTime);
//        return   this.page(page,lambdaQueryWrapper);
//    }

    public Page<Product> findIndex(int pageNo, int pageSize) {
        Page<Product> page = new Page<>(pageNo, pageSize);
        // 2 :设置查询条件
        LambdaQueryWrapper<Product> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 查询发布的轮播图信息
       // lambdaQueryWrapper.eq(Product::getStatus, 1);
        // 查询进行appsort的升序返回
//        lambdaQueryWrapper.orderByAsc(Product::getAppsort);
        // 3 :查询返回
        lambdaQueryWrapper.eq(Product::getStatus,1);
        lambdaQueryWrapper.orderByDesc(Product::getCreateTime);
        return   this.page(page,lambdaQueryWrapper);
    }

  /*  public Page<Product> findProductByPage(ProductVo productVo) {
        // 1: 设置查询分页的对象
        Page<Product> page = new Page<>(productVo.getPageNo(), productVo.getPageSize());
        // 2 : 设置查询条件
        LambdaQueryWrapper<Product> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 根据一级分类查询产品
        lambdaQueryWrapper.eq(productVo.getCategoryPid()!=null,Product::getCategoryPid,productVo.getCategoryPid());
        // 根据二级分类查询产品
        lambdaQueryWrapper.eq(productVo.getCategoryCid()!=null,Product::getCategoryCid,productVo.getCategoryCid());
        // 查询产品是发布的产品 status = 1
        lambdaQueryWrapper.eq(Product::getStatus,1);
        // 把最新的的产品查询出来
        lambdaQueryWrapper.orderByDesc(Product::getCreateTime);
        // 3: 调用分页查询，返回查询结构
        return this.page(page,lambdaQueryWrapper);
    }*/
}
